﻿using FixMath;
using UniFramework.Actor;
using UniFramework.Battle;
using UnityEngine;

namespace UniFramework.Buff
{
	/// <summary>
	/// 策划填表数据
	/// </summary>
	public struct BuffConfig
	{
		public string id;
		public string name;
		public int priority;
		public int maxStack;
		public string[] tags;
		public FixInt tickTime; //触发间隔
		public LogicActorProperty[] propMods; //当前Buff可以修改的角色数值
		public LogicActorControlState controlState; //当前buff可以修改的角色输入权限
		public BuffOnOccur onOccur;
		public BuffOnRemoved onRemoved;
		public BuffOnTick onTick;
		public BuffOnCast onCast;//角色释放技能时的回调，当技能释放时遍历所有buff的onCast接口，可以达到改变技能的效果
		public BuffOnHit onHit;
		public BuffOnBeHurt onBeHurt;
		public BuffOnKill onKill;
		public BuffOnBeKilled onBeKilled;

		public BuffConfig(
			string id, string name, string[] tags, int priority, int maxStack, FixInt tickTime,
			string onOccur = null,
			string onRemoved = null,
			string onTick = null,
			string onCast = null,
			string onHit = null,
			string beHurt = null,
			string onKill = null,
			string beKilled = null,
			LogicActorControlState controlState = null, LogicActorProperty[] propMods = null
		)
		{
			this.id = id;
			this.name = name;
			this.tags = tags;
			this.priority = priority;
			this.maxStack = maxStack;
			this.controlState = controlState;
			this.tickTime = tickTime;

			this.propMods = new LogicActorProperty[2]
			{
				LogicActorProperty.zero,
				LogicActorProperty.zero,
			};
			if (propMods != null)
			{
				for (int i = 0; i < Mathf.Min(2, propMods.Length); i++)
				{
					this.propMods[i] = propMods[i];
				}
			}

			this.onOccur = string.IsNullOrEmpty(onOccur) ? null : BuffData.onOccurFunc[onOccur];
			this.onRemoved = string.IsNullOrEmpty(onRemoved) ? null : BuffData.onRemovedFunc[onRemoved];
			this.onTick = string.IsNullOrEmpty(onTick) ? null : BuffData.onTickFunc[onTick];
			this.onCast = string.IsNullOrEmpty(onCast) ? null : BuffData.onCastFunc[onCast];
			this.onHit = string.IsNullOrEmpty(onHit) ? null : BuffData.onHitFunc[onHit];
			this.onBeHurt = string.IsNullOrEmpty(beHurt) ? null : BuffData.beHurtFunc[beHurt];
			this.onKill = string.IsNullOrEmpty(onKill) ? null : BuffData.onKillFunc[onKill];
			this.onBeKilled = string.IsNullOrEmpty(beKilled) ? null : BuffData.onBeKilledFunc[beKilled];
		}
	}


	public delegate void BuffOnOccur(BuffObj buff, int modifyStack); //buff在被添加，改变层数时触发的事件

	public delegate void BuffOnRemoved(BuffObj buff);

	public delegate void BuffOnTick(BuffObj buff);

	public delegate void BuffOnHit(BuffObj buff, ref DamageInfo damageInfo, LogicActor target);

	public delegate void BuffOnBeHurt(BuffObj buff, ref DamageInfo damageInfo, LogicActor attacker);

	public delegate void BuffOnKill(BuffObj buff, DamageInfo damageInfo, LogicActor target);

	public delegate void BuffOnBeKilled(BuffObj buff, DamageInfo damageInfo, LogicActor attacker);

	public delegate void BuffOnCast(BuffObj buff, ref Skill.Skill skill); //在释放技能时运行的buff，内部可对当前技能进行修改
}